(require :asdf)
(asdf:operate 'asdf:load-op :roll)
(use-package :roll/search/strips)

;; msvcrt.dll
(defun test ()
  (let ((problem (make-instance '<strips-problem>)))
    (defpredicate problem (on (<obj> ?a) (<obj> ?b)))
    (defpredicate problem (smaller (<obj> ?a) (<obj> ?b)))
    (defpredicate problem (clearp (<obj> ?a)))
    (defobjects problem
        (<obj>
         (<obj> <peg>)
         (<obj> <disk>)
         (<peg> peg1)
         (<peg> peg2)
         (<peg> peg3)
         (<disk> d1)
         (<disk> d2)
         (<disk> d3)))
    (definitial-state problem
                       ((smaller peg1 d1)
                        (smaller peg1 d2)
                        (smaller peg1 d3)
                        (smaller peg2 d1)
                        (smaller peg2 d2)
                        (smaller peg2 d3)
                        (smaller peg3 d1)
                        (smaller peg3 d2)
                        (smaller peg3 d3)
                        (smaller d2 d1)
                        (smaller d3 d1)
                        (smaller d3 d2)
                        
                        (clearp peg2)
                        (clearp peg3)
                        (clearp d1)
                        (on d3 peg1)
                        (on d2 d3)
                        (on d1 d2)))
    (defgoal-state problem
        (and (on d3 peg3)
             (on d2 d3)
             (on d1 d2)))
    (defaction problem
        :name move
        :parameters (?disk ?from ?to)
        :parameters-type (<disk> <obj> <obj>)
        :precondition (and (smaller ?to ?disk)
                           (on ?disk ?from)
                           (clearp ?disk)
                           (clearp ?to))
        :effect (and (clearp ?from)
                     (on ?disk ?to)
                     (not (on ?disk ?from))
                     (not (clearp ?to))))
    (let ((solver (make-instance 'roll/search/graph::<a*-graph-search-solver> :problem problem :heuristic #'(lambda (x p) 0))))
      (setq *solver* solver)
      (setq *problem* problem)
      ;;(roll/search/graph::solve solver problem)
      )))

(defun hoge (problem solver)
  (roll/search/graph:clear-nodes problem)
  (setf (roll/search/graph::close-list-of solver) nil)
  (setf (roll/search/graph::open-list-of solver) nil)
  (mapcar #'roll/search/graph::action-of (roll/search/graph::solve solver problem))
  )
